%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Note Figure A4 uses the dataset "data_figureA3.csv" generated from STATA
% file 0.clean_data.do. You need to run this .do file first.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

clc;    % Clear the command window.
close all;  % Close all figures (except those of imtool.)
clear;  % Erase all existing variables. Or clearvars if you want.

%Set the path below to the current folder in your directories
% Include your directories to the 'figures' sub-folder under the replication folder below: e.g. /Users/litang/Library/CloudStorage/Dropbox/RCT_Housing_new/data/replication/figures
 path(path,'INCLUDE DIRECTORY OF THE "FIGURES" SUB-FOLDER UNDER THE REPLICATION FOLDER')


filename = 'data_figureA4.csv';
mDATA = readtable(filename); % First row is a header
Font_size = 10;  
Line_width = 1.5;
%%

x0=100;
y0=1000;
width=1000;
height=600;


figure
subplot(2, 4, 1:2)
set(gcf,'position',[x0,y0,width,height])
histogram(mDATA.house_1,100,'BinLimits',[-100,100], 'Normalization','probability')
title('{Panel A: House price change forecast}','{over the next 12 months, \bf Baseline scenario}')
ylabel('Fraction')
xlabel('E\DeltaHP, %')
ylim([0 0.14])
set(gca,'box','off');
xline(27.8,'-','27.8%, mean E\DeltaHP (S1)','Color','red','LineWidth',2,'LabelOrientation','horizontal') 
set(gca,'box','off','FontSize',10);
 ax = gca;
ax.XGrid = 'off';
ax.YGrid = 'on';


subplot(2, 4, 3:4)
set(gcf,'position',[x0,y0,width,height])
histogram(mDATA.house_2,80,'BinLimits',[-100,100], 'Normalization','probability')
title('{Panel B: House price change forecast}','{over the next 12 months, \bf Shock scenario}')
ylim([0 0.14])
ylabel('Fraction')
xlabel('E\DeltaHP, %')
xline(26.7,'-','26.7%, mean E\DeltaHP (S2)','Color','red','LineWidth',2,'LabelOrientation','horizontal') 
set(gca,'box','off');
 ax = gca;
ax.XGrid = 'off';
ax.YGrid = 'on';

subplot(2, 4, 6:7)
histogram(mDATA.revision,80,'BinLimits',[-100,100], 'Normalization','probability')
title('{Panel C: Revision of house price change forecasts}')
ylabel('Fraction')
xlabel('Revison of E\DeltaHP, %')
xline(-1.1,'-','-1.1%, mean revision','Color','red','LineWidth',2,'LabelOrientation','horizontal') 
set(gca,'box','off');
 ax = gca;
ax.XGrid = 'off';
ax.YGrid = 'on';

set(gca,'box','off','FontSize',10);
dpi = 100;

width_in = width / dpi;
height_in = height / dpi;

set(gcf, 'PaperUnits', 'inches');
set(gcf, 'PaperSize', [width_in, height_in]);
set(gcf, 'PaperPosition', [0, 0, width_in, height_in]);
set(gcf, 'PaperPositionMode', 'manual');

saveas(gcf,'Figure_A3.pdf','pdf')